package hong.jun.pet_home.domain.util;


import hong.jun.pet_home.domain.org.Shop;

import java.util.Map;


public enum EmailMessageType {

    SHOP_SETTLED_NOTTICE(1, "商家入驻给公司发的邮件") {
        @Override
        public EmailMessage shopEvent(Shop shop) {
            EmailMessage message = new EmailMessage();
            message.setEmailtouser(shop.getAdmin().getEmail());
            message.setTitle("宠物之家");
            message.setTheme(" <h1>新的店铺入驻</h1>\n" +
                    "<h1>商铺名称---:" + shop.getName() + "</h1>\n" +
                    "<h2>商铺座机---:" + shop.getTel() + "</h2>\n" +
                    "<h2>商铺地址---:" + shop.getAddress() + "</h2>\n" +
                    "<h2>入驻时间---:" + shop.getRegisterTime() + "</h2>\n" +
                    "<h2>管理员账号---:" + shop.getAdmin().getUsername() + "</h2>\n" +
                    "<h2>管理员电话---:" + shop.getAdmin().getPhone() + "</h2>\n" +
                    "<h2>管理员邮箱---:" + shop.getAdmin().getEmail() + "</h2>\n" +
                    "<h2>管理员年龄---:" + shop.getAdmin().getAge() + "</h2>\n" +
                    "<h2>点击审核通过</h2>\n" +
                    "<a href='http://localhost:80/EMAIL/audityes/" + shop.getId() + "'>" +
                    "<img src='http://bpic.588ku.com/element_origin_min_pic/01/41/16/31573d2c5ab6d6a.jpg'/></a>" +
                    "<h2>点击审核驳回</h2>\n" +
                    "<a href='http://192.168.43.221:80/EMAIL/auditno/" + shop.getId() + "'>" +
                    "<img src='http://bpic.588ku.com/element_origin_min_pic/01/41/16/31573d2c5ab6d6a.jpg'/></a>");
            message.setReturnmessage("给公司发送邮件失败");
            return message;
        }

        @Override
        public EmailMessage mapEvent(Map<String, String> map) {
            return null;
        }
    },
    SHOP_SETTLED_PASS(2, "入驻通过给商家发的邮件") {
        @Override
        public EmailMessage shopEvent(Shop shop) {
            EmailMessage message = new EmailMessage();
            message.setEmailtouser(shop.getAdmin().getEmail());
            message.setTitle("宠物之家");
            message.setTheme(" <h1>审核通过</h1>\n" +
                    "<h1>商铺名称---:" + shop.getName() + "</h1>\n" +
                    "<h1>点击进行入驻</h1>\n" +
                    "<a href='http://localhost:80/common/auditend/" + shop.getId() + "'>" +
                    "<img src='http://5b0988e595225.cdn.sohucs.com/images/20191212/9ace3e2f1e8a46138d4f9b7a13968adf.jpeg'/></a>");
            message.setReturnmessage("用户激活邮件发送失败");
            return message;
        }

        @Override
        public EmailMessage mapEvent(Map<String, String> map) {
            return null;
        }
    },
    SHOP_SETTLED_REJECT(3, "入驻驳回给商家发的邮件") {
        @Override
        public EmailMessage shopEvent(Shop shop) {
            EmailMessage message = new EmailMessage();
            message.setEmailtouser(shop.getAdmin().getEmail());
            message.setTitle("宠物之家");
            message.setTheme(" <h1>审核驳回</h1>\n" +
                    "<h1>商铺名称---:" + shop.getName() + "</h1>\n" +
                    "<h1>宠物之家驳回你的入驻请求</h1>\n");
            message.setReturnmessage("用户激活邮件发送失败");
            return message;
        }

        @Override
        public EmailMessage mapEvent(Map<String, String> map) {
            return null;
        }
    },
    SHOP_FORBIDDEN(4, "店铺禁用给商家发的邮件") {
        @Override
        public EmailMessage shopEvent(Shop shop) {
            EmailMessage message = new EmailMessage();
            message.setEmailtouser(shop.getAdmin().getEmail());
            message.setTitle("宠物之家");
            message.setTheme(" <h1>禁用</h1>\n" +
                    "<h1>商铺名称---:" + shop.getName() + "</h1>\n" +
                    "<h1>宠物之家禁用你的入驻店铺</h1>\n");
            message.setReturnmessage("禁用用户邮件发送失败");
            return message;
        }

        @Override
        public EmailMessage mapEvent(Map<String, String> map) {
            return null;
        }
    },
    user_register_code(5, "用户注册的邮件验证码") {
        @Override
        public EmailMessage shopEvent(Shop shop) {
            return null;
        }

        @Override
        public EmailMessage mapEvent(Map<String, String> map) {
            if (map == null) {
                return null;
            }
            String email = null;
            String code = null;
            if (map.containsKey("email")) {
                email = map.get("email");
            }
            if (map.containsKey("code")) {
                code = map.get("code");
            }
            if (email == null || code == null) {
                return null;
            }
            EmailMessage message = new EmailMessage();
            message.setEmailtouser(email);
            message.setTitle("宠物之家");
            message.setTheme(" <h1>注册验证码</h1>\n" +
                    "<h1>您的验证码为:" + code + "</h1>\n" +
                    "<h1>有效期为5分钟</h1>\n");
            message.setReturnmessage("邮件验证码发送失败");
            return message;
        }
    },
    ;
    private final int type;//邮件类型
    private final String dec;//邮件描述


    public abstract EmailMessage shopEvent(Shop shop);//商铺邮件生成

    public abstract EmailMessage mapEvent(Map<String, String> map);//邮件生成

    EmailMessageType(int type, String dec) {
        this.type = type;
        this.dec = dec;
    }

}
